package com.itheima.solr.test;

import com.itheima.solr.pojo.Item;
import com.itheima.solr.pojo.Product;
import com.itheima.solr.tuils.ProductUtil;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

public class SolrTestImport {
    @Test
    public void test2() throws IOException, SolrServerException {
        //连接solr服务器
        HttpSolrServer httpSolrServer = new HttpSolrServer("http://localhost:8080/solr/test");
        //创建solr输入document
        List<Product> products = ProductUtil.file2list("140k_products.txt");

        //添加字段
        for (Product product : products) {
            httpSolrServer.addBean(product);
            httpSolrServer.commit();
        }

    }
}
